# api/models.py
from sqlalchemy import Column, Integer, String, DateTime, Enum
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
class User(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True, index=True)
    username = Column(String(50), unique=True, nullable=False)
    hashed_password = Column(String(255), nullable=False)
    nickname = Column(String(50), nullable=True)
    registration_date = Column(DateTime, nullable=True)
    last_login_date = Column(DateTime, nullable=True)
    login_count = Column(Integer, default=0)
    birthday = Column(String(10), nullable=True)  # 存储为字符串（格式：YYYY-MM-DD）
    gender = Column(Enum("male", "female", "other"), default="other")
    phone_number = Column(String(15), nullable=True)
    created_at = Column(DateTime, nullable=True)
    email = Column(String(120), unique=True, nullable=False)

    def __repr__(self):
        return f"<User(id={self.id}, username='{self.username}', email='{self.email}', nickname='{self.nickname}')>"